//
//  ADJgSDKInterstitialAdContainer.m
//  AnyThinkSDKDemo
//
//  Created by 刘娟 on 2024/9/25.
//  Copyright © 2024 抽筋的灯. All rights reserved.
//

#import "ADJgSDKInterstitialAdContainer.h"

@interface ADJgSDKInterstitialAdContainer()<ADJgSDKIntertitialAdDelegate>

@property(nonatomic, strong) ADJgSDKIntertitialAd *interstitialAd;

@property(nonatomic, assign) CGFloat bidPrice;

@end

@implementation ADJgSDKInterstitialAdContainer
-(void)setDelegate:(id<ADJgSDKIntertitialAdDelegate>)delegate{
    self.interstitialAd.delegate = delegate;
}
// MARK: - Init
-(instancetype)initPosId:(NSString *)posId delegate:(id<ADJgSDKIntertitialAdDelegate>)delegate{
    self = [super init];
    if(self){
        self.interstitialAd = [ADJgSDKIntertitialAd new];
        self.interstitialAd.posId = posId;
        self.interstitialAd.delegate = delegate;
        if (delegate == nil) {
            self.interstitialAd.delegate = self;
        }
    }
    return self;
}
- (void)loadInterstitialAd{
    if(self.interstitialAd){
        [self.interstitialAd loadAdData];
    }
}
- (void)showInterstitialAdWithRootViewController:(UIViewController *)controller{
    _interstitialAd.controller = controller;
    [_interstitialAd show];
}

- (void)close{
    _interstitialAd = nil;
}
- (NSInteger)getBidPrice{
    if (_interstitialAd == nil) {
        return 0;
    }
    return _bidPrice;
}
#pragma mark -- JgAdsInterstitialAdDelegate
/**
 *  开屏广告素材加载成功
 */
- (void)adjg_interstitialAdSuccedToLoad:(ADJgSDKIntertitialAd *)interstitialAd{
#if DEBUG
        NSLog(@"ADJgSDK - 插屏广告 - 加载成功");
#endif
    ADJgSDKExtInfo *extInfo = [interstitialAd adjg_extInfo];
    _bidPrice = extInfo.ecpm.floatValue;
    if ([self.containerDelegate respondsToSelector:@selector(jgsdkContainer_jgsdkInterstitialAdDidLoad:withPrice:)]) {
        [self.containerDelegate jgsdkContainer_jgsdkInterstitialAdDidLoad:self withPrice:_bidPrice];
    }
}

/**
 *  开屏广告请求失败
 */
- (void)adjg_interstitialAdFailedToLoad:(ADJgSDKIntertitialAd *)interstitialAd error:(ADJgAdapterErrorDefine *)error{
#if DEBUG
        NSLog(@"ADJgSDK - 插屏广告 - 加载失败：%@",error);
#endif
    if ([self.containerDelegate respondsToSelector:@selector(jgsdkContainer_jgsdkInterstitialAdFailLoadError:)]) {
        [self.containerDelegate jgsdkContainer_jgsdkInterstitialAdFailLoadError:nil];
    }
}
@end
